import React from 'react'
import { WeaPopoverHrm } from 'ecCom';
import { toJS } from 'mobx';
import {observer} from 'mobx-react';
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
@observer
export default class Main extends React.Component {
 
  //重新预测
  getForeCast = () => {
    const { smartGuessStore:{ getCellArr, setState } } = this.props;
    getCellArr({resetForecast: 1}); 
    setState({controlWranWrapFlag: false, needShowTip: false, needBtnMask: true});
  }
 
  //设置操作者信息面板隐藏
  setPanelVisible = () => {
    const { setHiddenSelectPanel } = this.props.smartGuessStore;
    setHiddenSelectPanel();
    let obj = document.getElementById('wfFrontOperator-container');
    if(obj) {
      obj.style.visibility = 'hidden'
    }
  } 

  getInfo(info) { 
    let str = getLabel('515119', '于&date&&time&在$nodename$节点预测，');
    str = str.toLowerCase();
    if(typeof str === 'string' ) {
      str = str.replace('&date&', ' ' + info.forecastDate + ' ');
      str = str.replace('&time&', ' ' + info.forecastTime + ' ');
      str = str.replace('$nodename$', ' ' + '"'  + info.forecastNodeName + '"'+  ' ');
      return str;
    } else {
      return '';
    }
  }
  
  render() {
    const { smartGuessStore } = this.props;
    const { forecastInfoMap, baseReqParams, needShowTip, smartGuessStatus, allMapshow, needForecastFunc} = smartGuessStore;
    let forecastInfo = {};
    if(forecastInfoMap.has(baseReqParams.requestid)) {
      forecastInfo = forecastInfoMap.get(baseReqParams.requestid);
    }
    return (
      <React.Fragment ecId={`${this && this.props && this.props.ecId || ''}_undefined@qqansf`}>
        {
            needForecastFunc 
            && smartGuessStatus 
            && !allMapshow 
            && needShowTip 
            && forecastInfo 
            && <div className='warn-top-info' onClick={this.setPanelVisible}>
              <p>
                <i className="icon-coms-Prompt" />
                {getLabel(515118,'当前流转由')}
                <a href={ `javaScript:openhrm(${forecastInfo.forecastUser})`} 
                  onClick={e => window.pointerXY(e)} 
                  className='operator'>{forecastInfo.forecastUserName}</a>
                {this.getInfo(forecastInfo)}
                
              </p>
            <a onClick={this.getForeCast}>{getLabel(515120, '点击这里重新预测')}</a>
          </div>
        }
      </React.Fragment>
    )
  }
}